package gogohome.ourhome;

import android.content.ContentValues; 
import android.content.Context; 
import android.database.Cursor; 
import android.database.SQLException; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
import android.util.Log; 



public class DbAdapter { 

	   

    public static final String KEY_TITLE = "title"; 

    public static final String KEY_ADDR = "addr";
    
    public static final String KEY_X = "x";
    
    public static final String KEY_Y = "y";

    public static final String KEY_ROWID = "_id"; 

   

    private static final String TAG = "NotesDbAdapter"; 

    private DatabaseHelper mDbHelper; 

    private SQLiteDatabase mDb; 

   

    /** 

     * Database creation sql statement 

     */ 

    private static final String DATABASE_CREATE = 

"create table bookmark (_id integer primary key autoincrement, " 

            + "title text not null, addr text not null,"
            + "x text not null, y text not null);";
    
    /*
    private static final String DATABASE_CREATE_ORDER = 

    	"create table ds_order (_id integer primary key autoincrement, " 
    	            + "estimatedTime text not null, fdistance text not null,"
    	            + "x text not null, y text not null);"; 
    */
    private static final String DATABASE_CREATE_ORDER =
    "CREATE TABLE ds_order (_ID INTEGER PRIMARY KEY  NOT NULL "
//    +",TYPE TEXT NOT NULL  DEFAULT ('HIGH') ,NAME TEXT"
    +",estimatedTime DATATIME NOT NULL DEFAULT (20) ,fDistance FLOAT NOT NULL  DEFAULT (0)"
    + ",nCharge INTEGER NOT NULL  DEFAULT (0) ," 
    + "nEarnMilage INTEGER NOT NULL  DEFAULT (0) ,nGoodsId INTEGER NOT NULL  DEFAULT (0) "
    + ",nPaymentType INTEGER NOT NULL  DEFAULT (0) ,orderTime DATETIME NOT NULL  DEFAULT (0) ,"
    + "reservationTime INTEGER NOT NULL  DEFAULT (0) ,strGuardianPhone TEXT NOT NULL  DEFAULT (0) ,"
    + "strPhone TEXT NOT NULL  DEFAULT (0) ,timeStamp DATETIME NOT NULL  DEFAULT (0),"
    + "destination INTEGER NOT NULL  DEFAULT (0) ,history INTEGER NOT NULL  DEFAULT (0),"
    + "orgin INTEGER NOT NULL  DEFAULT (0), provider INTEGER NOT NULL  DEFAULT (0))";
    
    private static final String DATABASE_CREATE_PLACE =
    	"CREATE TABLE place (Place_ID INTEGER PRIMARY KEY  NOT NULL "        
        +",fLatitude TEXT NOT NULL DEFAULT (0) ,fLongitude TEXT NOT NULL  DEFAULT (0)"           
        +",nDestUsage INTEGER NOT NULL DEFAULT (0) ,nOrginUsage INTEGER NOT NULL  DEFAULT (0)"
        + ",nTYPE INTEGER NOT NULL  DEFAULT (0)"
        + ",strAddress TEXT NOT NULL  DEFAULT (0)"
        + ",strPostcode TEXT NOT NULL  DEFAULT (0)"
        + ",strRepresentive TEXT NOT NULL  DEFAULT (0)"        
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0))";
        
    private static final String DATABASE_CREATE_HISTORY =
        "CREATE TABLE history (Orders_ID INTEGER PRIMARY KEY  NOT NULL "        
        +",lastedMessageTime DATATIME NOT NULL DEFAULT (0) ,nState INTEGER NOT NULL  DEFAULT (0)"
        +",nUnread INTEGER NOT NULL DEFAULT (0) ,receiptTime DATATIME NOT NULL  DEFAULT (0)"
        + ",strDriverPhone TEXT NOT NULL  DEFAULT (0)"
        //+ ",timeStamp DATATIME NOT NULL  DEFAULT (0)"
        //+ ",messages INTEGER NOT NULL  DEFAULT (0)"
        + ",strRepresentive TEXT NOT NULL  DEFAULT (0)"        
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0))";
//        + ",message INTEGER NOT NULL  DEFAULT (0)"
//        + ",order INTEGER NOT NULL  DEFAULT (0))";
    
    private static final String DATABASE_CREATE_MESSAGE =
        "CREATE TABLE message (M_ID INTEGER PRIMARY KEY  NOT NULL "        
    	+ ",nType INTEGER NOT NULL  DEFAULT (0)"        
        + ",strContent TEXT NOT NULL  DEFAULT (0)"
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0)"
        + ",history INTEGER NOT NULL  DEFAULT (0))";
        		
    private static final String DATABASE_CREATE_PROVIDER =
    	
        "CREATE TABLE provider (nID INTEGER PRIMARY KEY  NOT NULL "
    	+ ",fAveCashbackRate FLOAT NOT NULL  DEFAULT (0)"
    	+ ",fAveEstimatedTime FLOAT NOT NULL  DEFAULT (0)"
    	+ ",fAveThroughput FLOAT NOT NULL  DEFAULT (0)"
    	+ ",nFavoritesType INTEGER NOT NULL  DEFAULT (0)"
    	//+ ",nID INTEGER NOT NULL  DEFAULT (0)"
    	+ ",nMileage INTEGER NOT NULL  DEFAULT (0)"
    	+ ",nPastUsage INTEGER NOT NULL  DEFAULT (0)"
    	+ ",strName TEXT NOT NULL  DEFAULT (0)"
    	+ ",strPhone TEXT NOT NULL  DEFAULT (0)"
    	+ ",timeStamp TEXT NOT NULL  DEFAULT (0)"
    	+ ",iconImage INTEGER NOT NULL  DEFAULT (0))";
    	    
    
    
    private static final String DATABASE_NAME = "data"; 

    private static final String DATABASE_TABLE = "bookmark"; 

    private static final int DATABASE_VERSION = 2; 

   

    private final Context mCtx; 

   

    private static class DatabaseHelper extends SQLiteOpenHelper { 

   

        DatabaseHelper(Context context) { 

            super(context, DATABASE_NAME, null, DATABASE_VERSION); 

        } 

   

        @Override 

        public void onCreate(SQLiteDatabase db) { 

   

            //db.execSQL(DATABASE_CREATE); 
            //db.execSQL(DATABASE_CREATE);
            //
            db.execSQL(DATABASE_CREATE_MESSAGE);
            db.execSQL(DATABASE_CREATE_ORDER);
            db.execSQL(DATABASE_CREATE_PLACE);
            
            db.execSQL(DATABASE_CREATE_HISTORY);
            db.execSQL(DATABASE_CREATE_PROVIDER);
            

        } 

   

        @Override 

        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 

            Log.w(TAG, "Upgrading database from version " + oldVersion + " to " 

                    + newVersion + ", which will destroy all old data"); 

            db.execSQL("DROP TABLE IF EXISTS bookmark"); 

            onCreate(db); 

        } 

    } 

   

    public DbAdapter(Context ctx) { 

        this.mCtx = ctx; 

    } 

   

    public DbAdapter open() throws SQLException { 

        mDbHelper = new DatabaseHelper(mCtx); 

        mDb = mDbHelper.getWritableDatabase(); 

        return this; 

    } 

   

    public void close() { 

        mDbHelper.close(); 

    } 

   

    public long createNote(String title, String addr, String x, String y) { 

        ContentValues initialValues = new ContentValues(); 

        initialValues.put(KEY_TITLE, title); 

        initialValues.put(KEY_ADDR, addr);        
        initialValues.put(KEY_X, x);        
        initialValues.put(KEY_Y, y);   
        return mDb.insert(DATABASE_TABLE, null, initialValues); 
    } 

    public long createHistory(int Orders_ID, String lastedMessageTime, int nState, int nUnread, String receiptTime,String strDriverPhone, String timeStamp)    		    
    { 

        ContentValues initialValues = new ContentValues(); 

        initialValues.put("Orders_ID", Orders_ID);
        initialValues.put("lastedMessageTime", lastedMessageTime);
        initialValues.put("nState", nState);
        initialValues.put("receiptTime", receiptTime);
        initialValues.put("strDriverPhone", strDriverPhone);
        initialValues.put("timeStamp", timeStamp);        //initialValues.put("Orders_ID", Orders_ID);
        
        return mDb.insert("history", null, initialValues); 
    } 
    /*
    private static final String DATABASE_CREATE_HISTORY =
        "CREATE TABLE place (Orders_ID INTEGER PRIMARY KEY  NOT NULL "        
        +",lastedMessageTime DATATIME NOT NULL DEFAULT (0) ,nState INTEGER NOT NULL  DEFAULT (0)"
        +",nUnread INTEGER NOT NULL DEFAULT (0) ,receiptTime DATATIME NOT NULL  DEFAULT (0)"
        + ",strDriverPhone TEXT NOT NULL  DEFAULT (0)"
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0)"
        + ",messages INTEGER NOT NULL  DEFAULT (0)"
        + ",strRepresentive TEXT NOT NULL  DEFAULT (0)"        
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0)"
        + ",message INTEGER NOT NULL  DEFAULT (0)"
        + ",order INTEGER NOT NULL  DEFAULT (0))";
    */
    public long creatPlace(int Place_ID, String fLatitude, String fLongitude, int nDestUsage, int nOrginUsage, 
    		int nTYPE, String strAddress, String strPostcode, String strRepresentive, String timeStamp) { 

        ContentValues initialValues = new ContentValues(); 
        initialValues.put("Place_ID", Place_ID);
        initialValues.put("fLatitude", fLatitude); 
        initialValues.put("fLongitude", fLongitude);        
        initialValues.put("nDestUsage", nDestUsage);        
        initialValues.put("nOrginUsage", nOrginUsage);
        initialValues.put("nTYPE", nTYPE); 
        initialValues.put("strAddress", strAddress); 
        initialValues.put("strPostcode", strPostcode); 
        initialValues.put("strRepresentive", strRepresentive); 
        initialValues.put("timeStamp", timeStamp);  
        return mDb.insert("place", null, initialValues); 
    }    
    /*
    private static final String DATABASE_CREATE_PLACE =
        "CREATE TABLE place (Orders_ID INTEGER PRIMARY KEY  NOT NULL "        
        +",fLatitude FLOAT NOT NULL DEFAULT (0) ,fLongitude FLOAT NOT NULL  DEFAULT (0)"
        +",nDestUsage INTEGER NOT NULL DEFAULT (0) ,nOrginUsage INTEGER NOT NULL  DEFAULT (0)"
        + ",nTYPE INTEGER NOT NULL  DEFAULT (0)"
        + ",strAddress TEXT NOT NULL  DEFAULT (0)"
        + ",strPostcode TEXT NOT NULL  DEFAULT (0)"
        + ",strRepresentive TEXT NOT NULL  DEFAULT (0)"        
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0))";
    
    */
    public long creatProvider(int nID, float fAveCashbackRate, float fAveEstimatedTime, float fAveThroughput, int nFavoritesType, int nMileage, 
    		int nPastUsage, String strName, String strPhone, String timeStamp, int iconImage) { 

        ContentValues initialValues = new ContentValues(); 
        initialValues.put("nID", nID);
        initialValues.put("fAveEstimatedTime", fAveEstimatedTime); 
        initialValues.put("fAveThroughput", fAveThroughput);        
        initialValues.put("nFavoritesType", nFavoritesType);        
        initialValues.put("nMileage", nMileage);
        initialValues.put("nPastUsage", nPastUsage); 
        initialValues.put("strName", strName); 
        initialValues.put("strPhone", strPhone); 
        initialValues.put("timeStamp", timeStamp); 
        initialValues.put("iconImage", iconImage);  
        return mDb.insert("provider", null, initialValues); 
    }    
/*
    private static final String DATABASE_CREATE_PROVIDER =
    	
        "CREATE TABLE provider (nID INTEGER PRIMARY KEY  NOT NULL "
    	+ ",fAveCashbackRate FLOAT NOT NULL  DEFAULT (0)"
    	+ ",fAveEstimatedTime FLOAT NOT NULL  DEFAULT (0)"
    	+ ",fAveThroughput FLOAT NOT NULL  DEFAULT (0)"
    	+ ",nFavoritesType INTEGER NOT NULL  DEFAULT (0)"
    	+ ",nID INTEGER NOT NULL  DEFAULT (0)"
    	+ ",nMileage INTEGER NOT NULL  DEFAULT (0)"
    	+ ",nPastUsage INTEGER NOT NULL  DEFAULT (0)"
    	+ ",strName TEXT NOT NULL  DEFAULT (0)"
    	+ ",strPhone TEXT NOT NULL  DEFAULT (0)"
    	+ ",timeStamp TEXT NOT NULL  DEFAULT (0)"
    	+ ",iconImage INTEGER NOT NULL  DEFAULT (0))";
    	
    	*/
    public long createMessage(int M_ID, int ntype, String strContent, String timeStamp, int history_id) { 

        ContentValues initialValues = new ContentValues(); 

        initialValues.put("M_ID", M_ID); 
        initialValues.put("nType", ntype);        
        initialValues.put("strContent", strContent);        
        initialValues.put("timeStamp", timeStamp);
        initialValues.put("history", history_id);  
        return mDb.insert("message", null, initialValues); 
    }
    
    public long creatOrder(int order_id, String estimatedTime, float fDistance, int nCharge, int nEarnMilage,int nGoodsId,
    					   int nPaymentType, String orderTime, String reservationTime, String strGuardianPhone, String strPhone, String timeStamp,
    					   int destination, int history, int orgin, int provider){ 
    					   //String strContent, String timeStamp, int history_id) { 

        ContentValues initialValues = new ContentValues(); 

        initialValues.put("_ID", order_id); 
        initialValues.put("estimatedTime", estimatedTime);
        initialValues.put("fDistance", fDistance);
        initialValues.put("nCharge", nCharge);        
        initialValues.put("nEarnMilage", nEarnMilage);
        initialValues.put("nGoodsId", nGoodsId);                
        initialValues.put("nPaymentType", nPaymentType);
        initialValues.put("orderTime", orderTime);
        initialValues.put("reservationTime", reservationTime);
        initialValues.put("strGuardianPhone", strGuardianPhone);
        initialValues.put("strPhone", strPhone);
        initialValues.put("timeStamp", timeStamp);
        initialValues.put("destination", destination);
        initialValues.put("history", history);
        initialValues.put("orgin", orgin);
        initialValues.put("provider", provider);
        
        return mDb.insert("ds_order", null, initialValues); 
    }    
 //   private static final String DATABASE_CREATE_ORDER =
//        "CREATE TABLE ds_order (_ID INTEGER PRIMARY KEY  NOT NULL "
//        +",TYPE TEXT NOT NULL  DEFAULT ('HIGH') ,NAME TEXT"
//        +",estimatedTime DATATIME NOT NULL DEFAULT (20) ,fDistance FLOAT NOT NULL  DEFAULT (0)"
//        + ",nCharge INTEGER NOT NULL  DEFAULT (0) ," 
//        + "nEarnMilage INTEGER NOT NULL  DEFAULT (0) ,nGoodsId INTEGER NOT NULL  DEFAULT (0) "
//        + ",nPaymentType INTEGER NOT NULL  DEFAULT (0) ,orderTime DATETIME NOT NULL  DEFAULT (0) ,"
//        + "reservationTime INTEGER NOT NULL  DEFAULT (0) ,strGuardianPhpne TEXT NOT NULL  DEFAULT (0) ,"
//        + "strPhone TEXT NOT NULL  DEFAULT (0) ,timeStamp DATETIME NOT NULL  DEFAULT (0)"
//        + "destination INTEGER NOT NULL  DEFAULT (0) ,history INTEGER NOT NULL  DEFAULT (0)"
//        + "orgin INTEGER NOT NULL  DEFAULT (0), provider INTEGER NOT NULL  DEFAULT (0))";    
//    private static final String DATABASE_CREATE_MESSAGE =
 //       "CREATE TABLE place (Orders_ID INTEGER PRIMARY KEY  NOT NULL "        
   // 	+ ",nType INTEGER NOT NULL  DEFAULT (0))"        
    //    + ",strContent TEXT NOT NULL  DEFAULT (0)"
    //    + ",timeStamp DATATIME NOT NULL  DEFAULT (0)"
    //    + ",history INTEGER NOT NULL  DEFAULT (0))";   

    
    public boolean updateMessage(int M_ID, int ntype, String strContent, String timeStamp, int history_id) { 

        ContentValues args = new ContentValues(); 

        args.put("M_ID", M_ID);
        
        args.put("nType", ntype);

        args.put("strContent", strContent);
        
        args.put("timeStamp", timeStamp);
        
        args.put("history", history_id);

   

        return mDb.update("message", args, null, null) > 0; 

    }     
    

    public boolean deleteNote(long rowId) { 
        Log.i("Delete called", "value__" + rowId); 
        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0; 
    } 

   

    public Cursor fetchAllNotes() { 

   

        return mDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_TITLE, 

                KEY_ADDR, KEY_X, KEY_Y }, null, null, null, null, null); 

    } 

    //public long creatPlace(int Place_Id, String fLatitude, String fLongitude, int nDestUsage, int nOrginUsage, 
    		//int nTYPE, String strAddress, String strPostcode, String strRepresentive, String timeStamp)   
    
    public Cursor fetchAllPlace() { 

 	   

        return mDb.query("place", new String[] { "Place_ID", "fLatitude", 

        		"fLongitude", "nDestUsage", "nOrginUsage", "nTYPE", "strAddress", "strPostcode", "strRepresentive", "timeStamp"}, null, null, null, null, null); 

    }
    
     
    public Cursor fetchPlace(String address) { 

    	Cursor mCursor = 

         mDb.query("place", new String[] { "Place_ID", "fLatitude", 
        		 										

        		"fLongitude", "nDestUsage", "nOrginUsage", "nTYPE", "strAddress", "strPostcode", "strRepresentive", "timeStamp"}, "strAddress = '"+address+"'", null, null, null, null);

    	if (mCursor != null) { 

            mCursor.moveToFirst(); 

        } 
    	
    	return mCursor;

    }
    public Cursor fetchPlaceOrder() { 

    	Cursor mCursor = 

         mDb.query("place", new String[] { "Place_ID", "fLatitude", 
        		 										

        		"fLongitude", "nDestUsage", "nOrginUsage", "nTYPE", "strAddress", "strPostcode", "strRepresentive", "timeStamp"}, null, null, null, null, "nDestUsage desc");

    	if (mCursor != null) { 

            mCursor.moveToFirst(); 

        } 
    	
    	return mCursor;

    }   
    /*
    private static final String DATABASE_CREATE_PLACE =
    	"CREATE TABLE place (Place_ID INTEGER PRIMARY KEY  NOT NULL "        
        +",fLatitude TEXT NOT NULL DEFAULT (0) ,fLongitude TEXT NOT NULL  DEFAULT (0)"
        +",nDestUsage INTEGER NOT NULL DEFAULT (0) ,nOrginUsage INTEGER NOT NULL  DEFAULT (0)"
        + ",nTYPE INTEGER NOT NULL  DEFAULT (0)"
        + ",strAddress TEXT NOT NULL  DEFAULT (0)"
        + ",strPostcode TEXT NOT NULL  DEFAULT (0)"
        + ",strRepresentive TEXT NOT NULL  DEFAULT (0)"        
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0))";
    */
    
    
    public Cursor fetchprovider(int Provider_ID){

    	Cursor mCursor = 

    		mDb.query("provider", new String[] { "nID", "fAveCashbackRate", "fAveEstimatedTime", "fAveThroughput", 
        			
        			"nFavoritesType", "nMileage", "nPastUsage", "strName", "strPhone", "timeStamp", "iconImage"}
            		
            		,"nID = '"+Provider_ID+"'", null, null, null, null); 
	
    		

 
    	if (mCursor != null) { 

            mCursor.moveToFirst(); 

        } 

    	return mCursor;
    
    }

    
    public Cursor fetchAllProvider() { 

  	   

        return mDb.query("provider", new String[] { "nID", "fAveCashbackRate", 

        		"fAveEstimatedTime", "fAveThroughput", "nFavoritesType", "nMileage", "nPastUsage", "strName", "strPhone", "timeStamp", "iconImage"}
        		
        		, null, null, null, null, null); 

    }
    /*
    "CREATE TABLE provider (Orders_ID INTEGER PRIMARY KEY  NOT NULL "
	+ ",fAveCashbackRate FLOAT NOT NULL  DEFAULT (0)"
	+ ",fAveEstimatedTime FLOAT NOT NULL  DEFAULT (0)"
	+ ",fAveThroughput FLOAT NOT NULL  DEFAULT (0)"
	+ ",nFavoritesType INTEGER NOT NULL  DEFAULT (0)"
	+ ",nID INTEGER NOT NULL  DEFAULT (0)"
	+ ",nMileage INTEGER NOT NULL  DEFAULT (0)"
	+ ",nPastUsage INTEGER NOT NULL  DEFAULT (0)"
	+ ",strName TEXT NOT NULL  DEFAULT (0)"
	+ ",strPhone TEXT NOT NULL  DEFAULT (0)"
	+ ",timeStamp TEXT NOT NULL  DEFAULT (0)"
	+ ",iconImage INTEGER NOT NULL  DEFAULT (0))";
    */
    /*
    private static final String DATABASE_CREATE_PLACE =
        "CREATE TABLE place (Orders_ID INTEGER PRIMARY KEY  NOT NULL "        
        +",fLatitude FLOAT NOT NULL DEFAULT (0) ,fLongitude FLOAT NOT NULL  DEFAULT (0)"
        +",nDestUsage INTEGER NOT NULL DEFAULT (0) ,nOrginUsage INTEGER NOT NULL  DEFAULT (0)"
        + ",nTYPE INTEGER NOT NULL  DEFAULT (0)"
        + ",strAddress TEXT NOT NULL  DEFAULT (0)"
        + ",strPostcode TEXT NOT NULL  DEFAULT (0)"
        + ",strRepresentive TEXT NOT NULL  DEFAULT (0)"        
        + ",timeStamp DATATIME NOT NULL  DEFAULT (0))";
    */
    public Cursor fetchAllMessages() { 

    	Cursor mCursor =    

         mDb.query("message", new String[] { "M_ID", "nType", 

        		"strContent", "timeStamp", "history" }, null, null, null, null, null);
    	if (mCursor != null) { 

            mCursor.moveToFirst(); 

        } 

    	
    	
    	return mCursor;

    }
    
    public Cursor fetchMessage(int history_id) { 

    	Cursor mCursor = 

         mDb.query("message", new String[] { "M_ID", "nType", 

        		"strContent", "timeStamp", "history" }, "history = '"+history_id+"'", null, null, null, null);
    	
        if (mCursor != null) { 

            mCursor.moveToFirst(); 

        } 
    	
    	
    	return mCursor;

    }

    public Cursor fetchAllOrders() { 

 	   

        return mDb.query("ds_order", new String[] { "_ID", "estimatedTime", 

        		"fDistance", "nCharge", "nEarnMilage","nGoodsId", "nPaymentType", "orderTime", "reservationTime", 
        		"strGuardianPhone", "strPhone", "timeStamp", "destination", "history", "orgin", "provider"   }, null, null, null, null, null); 

    }    

    public Cursor fetchOrders(int provider) { 

    	Cursor mCursor = 

         mDb.query("ds_order", new String[] { "_ID", "estimatedTime", 

        		"fDistance", "nCharge", "nEarnMilage","nGoodsId", "nPaymentType", "orderTime", "reservationTime", 
        		"strGuardianPhone", "strPhone", "timeStamp", "destination", "history", "orgin", "provider"   }, 
        		"provider = '"+provider+"'", null, null, null, null);
    	
        if (mCursor != null) { 

            mCursor.moveToFirst(); 

        }
    	
    	return mCursor;

    }   
    
    
    
    public Cursor fetchNote(long rowId) throws SQLException { 

   

        Cursor mCursor = 

   

        mDb.query(true, DATABASE_TABLE, new String[] { KEY_ROWID, KEY_TITLE, 

                KEY_ADDR, KEY_X, KEY_Y}, KEY_ROWID + "=" + rowId, null, null, null, null, 
                

                null); 

        if (mCursor != null) { 

            mCursor.moveToFirst(); 

        } 

        return mCursor; 

   

    } 


    public boolean updateProvider(int nID, float fAveCashbackRate, float fAveEstimatedTime, float fAveThroughput, int nFavoritesType, int nMileage,  
    		int nPastUsage, String strName, String strPhone, String timeStamp, int iconImage){    	    		    		
    		//long rowId, String title, String addr, String x, String y) { 
        ContentValues args = new ContentValues(); 

        args.put("nID", nID);         
        args.put("fAveCashbackRate", fAveCashbackRate);
        args.put("fAveEstimatedTime", fAveEstimatedTime);
        args.put("fAveThroughput", fAveThroughput);
        args.put("nMileage", nMileage);
        args.put("nPastUsage", nPastUsage);
        args.put("strName", strName);
        args.put("strPhone", strPhone);

        args.put("timeStamp", timeStamp);
        
        args.put("iconImage", iconImage);

        
        
        return mDb.update("provider", args, "nID = "+nID, null) > 0; 
    } 

    
    public boolean updatePlace(int Place_ID, String fLatitude, String fLongitude, int nDestUsage, int nOrginUsage, 
    		int nTYPE, String strAddress, String strPostcode, String strRepresentive, String timeStamp){    	    		    		
    		//long rowId, String title, String addr, String x, String y) { 
        ContentValues args = new ContentValues(); 

        //ContentValues initialValues = new ContentValues(); 
        args.put("Place_ID", Place_ID);
        args.put("fLatitude", fLatitude); 
        args.put("fLongitude", fLongitude);        
        args.put("nDestUsage", nDestUsage);        
        args.put("nOrginUsage", nOrginUsage);
        args.put("nTYPE", nTYPE); 
        args.put("strAddress", strAddress); 
        args.put("strPostcode", strPostcode); 
        args.put("strRepresentive", strRepresentive); 
        args.put("timeStamp", timeStamp); 
        
        
        return mDb.update("place", args, "Place_ID = "+Place_ID, null) > 0; 
    } 

    
    

    public boolean updateNote(long rowId, String title, String addr, String x, String y) { 

        ContentValues args = new ContentValues(); 

        args.put(KEY_TITLE, title); 

        args.put(KEY_ADDR, addr);
        
        args.put(KEY_X, x);
        
        args.put(KEY_Y, y);

   

        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0; 

    } 

} 
 

